package com.hzh.serviceImpl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hzh.entity.FileEntity;
import com.hzh.mapper.FileMapper;
import com.hzh.service.FileService;
import com.hzh.util.HgMultipartFile;
/**
 * service实现类
 * @author xiaohua
 */
@Service
public class FileServiceImpl implements FileService {
    @Autowired
    private FileMapper fileMapper;

	@Override
	public int create(FileEntity fileEntity) {
		return fileMapper.create(fileEntity);
	}

	@Override
	public int update(FileEntity fileEntity) {
		return fileMapper.update(fileEntity);
	}

	@Override
	public List<FileEntity> getList(Map<String, Object> map) {
		return fileMapper.getList(map);
	}

	@Override
	public int getTotal(Map<String, Object> map) {
		return fileMapper.getTotal(map);
	}
	
	@Override
    public void saveSingleFileUpload(Map<String, String> vo,
        ArrayList<HgMultipartFile> multipartList,String fileSavePath) throws Exception {
        
        for (HgMultipartFile file : multipartList) {
            saveFileInput(file,fileSavePath);
        }
    }
	private void saveFileInput(HgMultipartFile file,String fileSavePath) throws Exception {
        //demo将文件存放到文件路径下
        FileUtils.copyInputStreamToFile(file.getInputStream(), new File(fileSavePath));
    }

	@Override
	public FileEntity getByFileId(String fileId) {
		return fileMapper.getByFileId(fileId);
	}
}

